{% extends "main.html" %}
{% block body %}
    <div id="login">
        <div class="login-row">
            <h2>找回密码</h2>
        </div>
        <div class="login-row">
            <input class="form-control" type="text" name="email" id="email" placeholder="邮箱">
        </div>
        <div class="login-row">
            <button id="send_email" class="btn btn-success btn-block" type="button">发送「重置密码」邮件</button>
        </div>
        <div class="login-row">
            <button id="back" class="btn btn-block" type="button">返回</button>
        </div>
    </div>

{% endblock %}

{% block script %}
    <script>
        $('#send_email').click(function () {
            send_email()
        })
        $('#back').click(function () {
            relocation('/')
        })

        $('#email').onkeydown = function (event) {
            var e = event || window.event || arguments.callee.caller.arguments[0];
            if (e && e.keyCode == 27) { // 按 Esc
                //要做的事情
            }
            if (e && e.keyCode == 113) { // 按 F2
                //要做的事情
            }
            if (e && e.keyCode == 13) { // enter 键
                //要做的事情
                send_email()
            }
        };

        function send_email() {
            email = $('#email').val()
            password = $('#password').val()
            if (email == '') {
                toast('请输入邮箱')
                return false
            }
            ipreg = /^[\.a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/
            if (!ipreg.test(email)) {
                toast('输入邮箱格式有误，请检查确认')
                return false
            }
            $.ajax({
                url: "{{ url_for('auth.send_email') }}",
                type: "post",
                data: {
                    'email': email,
                },
                success: function (result) {
                    toast('邮件已发送，请注意查收')
                    setTimeout('relocation("/")', 1000)
                },
                error: function (result) {
                    toast(result.responseText)
                }
            })
        }
    </script>
{% endblock %}
